<?php

class Story_Widget_CreateComicsStoryController extends
    Engine_Content_Widget_Abstract
{

    public function indexAction()
    {
    	$story = null;
    	if( Engine_Api::_()->core()->hasSubject() ) {
    		$story = Engine_Api::_()->core()->getSubject();
    			
//     		if($story->category_id != Story_Model_Category::COMICS){
//     			$this->setNoRender();
//     		}
    		
    		if(!$story->canView(Story_Model_Category::COMICS)){
    			return $this->setNoRender();
    		}
    		
    	}
    	
        $viewer = Engine_Api::_()->user()->getViewer();
        $this->view->can_create = Engine_Api::_()->authorization()->isAllowed('story', $viewer, 'create');

        if (!$this->view->can_create) {
            return $this->setNoRender();
        }
        
        $this->view->form = new Story_Form_Create_Custom(array(
                'category' => Story_Model_Category::COMICS,
                'tit' => 'Comics',
                ));
        
        $photo_url = "";
        $photo_id = 0;
        $story_id = 0;
        $title = "";
        $description = "";
        
        if($story){
        	$photo = $story->getPhoto();
        	$photo_url = $photo->getPhotoUrl();
        	$photo_id = $story->photo_id;
        	$story_id = $story->getIdentity();
        	$title = $story->getTitle();
        	$description = $story->getDescription();
        }   
        
        //Just for testing
        //$photo_url = "application/modules/Story/externals/images/trafalgar-square-annotated.jpg";
        //$story_id = 1;
        //$photo_id = 1;
        //End Testing
        
        
        $this->view->photo_url = $photo_url;
        $this->view->photo_id  = $photo_id;
        $this->view->story_id  = $story_id;
        $this->view->title  = $title;
        $this->view->description  = $description;
    }

}
